#include"stm32f4xx.h"
#include"main.h"
unsigned int Timedelay = 0;

void Systick_Init(void)
{
	SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
	//SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
	if(SysTick_Config(SystemCoreClock/1000))
	{
		Beep_Open();
	}
}

void my_delay_ms(unsigned int num)
{
	Timedelay=num;
	while(Timedelay!=0);
}

void SysTick_Handler(void)
{
	if(Timedelay!=0)
		Timedelay--;
}

void delay_ms_1(int nms)
{
	SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
	SysTick->CTRL &=~(1<<0);
	SysTick->LOAD = nms*21000-1;
	SysTick->VAL = 0;
	SysTick->CTRL |= (1<<0);
	while((SysTick->CTRL&0x00010000) == 0);
	SysTick->VAL = 0;
	SysTick->CTRL = 0;
}

void delay_us_1(int nms)
{
	SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
	SysTick->CTRL &=~(1<<0);
	SysTick->LOAD = nms*21000/1000-1;
	SysTick->VAL = 0;
	SysTick->CTRL |= (1<<0);
	while((SysTick->CTRL&0x00010000) == 0);
	SysTick->VAL = 0;
	SysTick->CTRL = 0;
}